package com.ylr.config.config;

import com.ylr.user.framework.feign.client.YuUserClient;
import com.ylr.base.framework.interceptor.AuthInterceptor;
import com.ylr.base.framework.interceptor.CommonInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-04-21 18:14:52
 * className: WebConfig web mvc配置类
 * version: 1.0
 * description:
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Lazy
    @Resource
    private YuUserClient yuUserClient;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加公共拦截器，拦截所有请求
        registry.addInterceptor(new CommonInterceptor())
                .addPathPatterns("/**");
        // 添加用户拦截器，拦截所有请求
        registry.addInterceptor(new AuthInterceptor(yuUserClient))
                .addPathPatterns("/**");
    }


}
